<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 分页
 */
if (!function_exists('pager')) {

    function pager($current_page, $sum, $size)
    {
        $size = intval($size);
        $current_page = intval($current_page);
        $sum = intval($sum);

        $sum_page = ceil($sum / $size); //总共页数
        if ($current_page <= 1) {
            $current_page = 1;
        }
        if ($current_page > $sum_page) {
            $current_page = $sum_page;
        }

        $page_html = "<div class=\"m-page m-page-sr m-page-sm m-page-rt\">";
        if ($current_page == 1) {
            $page_html .= "<a href=\"#\" class=\"first pageprv z-dis\"><span class=\"pagearr\">&lt;</span>上一页</a>";
        } else {
            $page_html .= "<a href=\"#\" class=\"first pageprv\"><span class=\"pagearr\">&lt;</span>上一页</a>";
        }
        for ($i = 1; $i <= $sum_page; $i++) {
            if ($i == $current_page) {
                $page_html .= "<a href=\"#\" class=\"z-crt\">$i</a>";
            } else {
                $page_html .= "<a href=\"#\">$i</a>";
            }
        }
        if ($current_page == $sum_page) {
            $page_html .= "<a href=\"#\" class=\"last pagenxt z-dis\">下一页<span class=\"pagearr\">&gt;</span></a>";
        } else {
            $page_html .= "<a href=\"#\" class=\"last pagenxt\">下一页<span class=\"pagearr\">&gt;</span></a>";
        }
        $page_html .= "</div>";
        return $page_html;
    }
}